#include <motorlogic.h>
//LD293
const int moterLogic1a = 2;
const int moterLogic1b = 3;
const int moterLogic1e = 9;
const int moterLogic2a = 4;
const int moterLogic2b = 5;
const int moterLogic2e = 10;

const int ledPin = 13;

const int sensRR = 2;
const int sensMR = 3;
const int sensML = 4:
const int sensLL = 5;
const int sensHI = 0;
int speed;

void setup() {
  // put your setup code here, to run once:
  pinMode(ledPin, OUTPUT);
  pinMode(moterLogic1a, OUTPUT);
  pinMode(moterLogic1b, OUTPUT);
  pinMode(moterLogic1e, OUTPUT);
  pinMode(moterLogic2a, OUTPUT);
  pinMode(moterLogic2b, OUTPUT);
  pinMode(moterLogic2e, OUTPUT);
  
  blink(3);
}

void loop() {
  // put your main code here, to run repeatedly: 
  forward(255);
  delay(2000);
  stopp();
  backward(255);
  delay(2000);
  stopp();
  right(255);
  delay(2000);
  stopp();
  left(255);
  delay(2000);
  stopp();
  while(1);
  

}

void forward(int speed){
  setMotorLogic(HIGH, LOW, HIGH, LOW);
  setSpeed(speed);
}

void backward(int speed){
  setMotorLogic(LOW, HIGH, LOW, HIGH);
  setSpeed(speed);
}

void right(int speed){
  setMotorLogic(HIGH, LOW, LOW, LOW);
  setSpeed(speed);
}

void left(int speed){
  setMotorLogic(LOW, LOW, HIGH, LOW);
  setSpeed(speed);
}

void stopp() { 
  setSpeed(0);
  delay(500);
}

void set(byte pin, byte value){
 digitalWrite(pin, value); 
}

void setMotorLogic(byte m11, byte m12, byte m21, byte m22){
  set(moterLogic1a,m11);
  set(moterLogic1b,m12);
  set(moterLogic2a,m21);
  set(moterLogic2b,m22);
}

void setSpeed(int speed) {
  analogWrite(moterLogic1e, speed);
  analogWrite(moterLogic2e, speed);
}

void blink(int a) {
  for(int i=0;i<a;i++){ 
    set(ledPin, HIGH);   // set the LED on
    delay(100);              // wait for a second
    set(ledPin, LOW);    // set the LED off
    delay(350);              // wait for a second 
  }
}

